package com.topboya.linker.ui.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.TextView;

import com.topboya.linker.R;
import com.topboya.linker.model.levelitem.DepartmentGroupBo;
import com.topboya.linker.model.levelitem.SelectVistorItem;
import com.topboya.linker.model.response.CustomerByOrgIdResponse;
import com.topboya.linker.utils.LogUtils;

import java.util.List;

public class SelectedDepartListAdapter extends RecyclerView.Adapter<SelectedDepartListAdapter.ListItemViewHolder> {

    private static final String TAG = "SelectedDepartListAdapter:";
    private  List<SelectVistorItem> departmentListselected;

    public SelectedDepartListAdapter(List<SelectVistorItem> departmentListselected) {

        this.departmentListselected = departmentListselected;

    }

    @Override
    public ListItemViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {

        View itemView = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.selected_departlist, viewGroup, false);
        return new ListItemViewHolder(itemView);

    }


    //绑定界面，设置监听
    @Override
    public void onBindViewHolder(final ListItemViewHolder holder, final int i) {

        LogUtils.v(TAG+"departmetGroupList---:"+departmentListselected.toString());
        //点击事件监听

        holder.tv_selected_departlist.setText(departmentListselected.get(i).getCusName());

        clickListenter(holder, i);

    }

    private void clickListenter(ListItemViewHolder holder, int i) {
        holder.itemView.setOnClickListener(v -> {

            if (null !=itemClickListener){
                itemClickListener.onClick(holder.itemView,i);
            }
        });

        holder.img_delete_selected_depart.setOnClickListener(v -> {

             onItemChildClickListener.onClick(holder.img_delete_selected_depart,i);
        });
    }

    @Override
    public int getItemCount() {

        return departmentListselected == null ? 0 : departmentListselected.size();
    }

    public class ListItemViewHolder extends RecyclerView.ViewHolder{

        //ViewHolder
        TextView tv_selected_departlist;
        ImageView img_delete_selected_depart;

        ListItemViewHolder(View view) {

            super(view);
            this.tv_selected_departlist = view.findViewById(R.id.tv_selected_departlist);
            this.img_delete_selected_depart = view.findViewById(R.id.img_delete_selected_depart);

        }

    }


    private OnItemClickListener itemClickListener;

    public void setOnItemClickListener(SelectedDepartListAdapter.OnItemClickListener itemClickListener){

        this.itemClickListener = itemClickListener;
    }

    public interface  OnItemClickListener{

        void onClick(View v, int position);
    }


    private OnItemChildClickListener onItemChildClickListener;

    public void setOnItemChildClickListener(OnItemChildClickListener onItemChildClickListener){

        this.onItemChildClickListener = onItemChildClickListener;
    }

    public interface  OnItemChildClickListener{

        void onClick(View v, int position);
    }


}
